<?php

namespace App\Http\Middleware;

use Closure;

class LoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $action = substr(\Route::currentRouteAction(),strpos(\Route::currentRouteAction(),'@')+1); //获取当前的方法名称
        if(empty(\Session::get('user')))
        {
            $request->session()->push('target_url', $action);//保存一下跳转的地址
            return redirect(url('user'));
        }
        return $next($request);
    }
}
